<!--
  ~ This program is part of the OpenLMIS logistics management information system platform software.
  ~ Copyright © 2013 VillageReach
  ~
  ~ This program is free software: you can redistribute it and/or modify it under the terms of the GNU Affero General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
  ~  
  ~ This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Affero General Public License for more details.
  ~ You should have received a copy of the GNU Affero General Public License along with this program.  If not, see http://www.gnu.org/licenses.  For additional information contact info@OpenLMIS.org. 
  -->

<div id="parameterizedReport">
  <h2 id="reportName" ng-bind="template.name"></h2>

  <div class="table-container">
    <table id="reportParametersTable" ng-if="parameters.length" class="table table-bordered table-striped">
      <thead>
        <tr class="gradient-header">
          <th openlmis-message="header.parameter"></th>
          <th openlmis-message="header.parameter.value"></th>
          <th openlmis-message="header.parameter.description"></th>
        </tr>
      </thead>
      <tbody>
        <tr ng-repeat="parameter in parameters" class="form-row">
          <td id="displayName_{{parameter.name}}" class="span4" ng-bind="parameter.displayName"></td>

          <td class="span4">
            <div ng-if="parameter.dataType === 'java.lang.Integer' ||
                  parameter.dataType === 'java.lang.Short' ||
                  parameter.dataType === 'java.lang.Long'" class="position-relative">
              <input id="integer_{{parameter.name}}" type="text" name="int_{{parameter.name}}" class="right-justified"
                     ng-model="parameterMap[parameter.name]" ng-change="refreshParams()"
                     numeric-validator="integer,100" ng-trim="false"/>
              <span id="int_{{parameter.name}}" class="rnr-form-error" style="display:none;"
                    openlmis-message="error.number.only"></span>
            </div>

            <div ng-if="parameter.dataType === 'java.lang.Boolean'">
              <input id="true_{{parameter.name}}" type="radio" name="{{parameter.name}}" ng-value="'true'"
                     ng-model="parameterMap[parameter.name]" ng-change="refreshParams()"/>
              <strong openlmis-message="button.yes"></strong> &nbsp; &nbsp; &nbsp;

              <input id="false_{{parameter.name}}" type="radio" name="{{parameter.name}}" ng-value="'false'"
                     ng-model="parameterMap[parameter.name]" ng-change="refreshParams()"/>
              <strong openlmis-message="button.no"></strong>
            </div>

            <div ng-if="parameter.dataType === 'java.util.Date'">
              <input id="date_{{parameter.name}}" type="text" name="date" ng-change="refreshParams()"
                     ui-date="{dateFormat: 'dd/mm/yy', changeYear: true}" ui-date-format="dd/mm/yy"
                     ng-model="parameterMap[parameter.name]" readonly/>
            </div>

            <div ng-if="parameter.dataType === 'java.lang.Float' ||
                  parameter.dataType === 'java.lang.Double' ||
                  parameter.dataType === 'java.math.BigDecimal'" class="position-relative">
              <input id="float_{{parameter.name}}" type="text" numeric-validator="numericValue,100,100"
                     class="right-justified"
                     name="f_{{parameter.name}}"
                     ng-model="parameterMap[parameter.name]" ng-change="refreshParams()"/>
              <span class="rnr-form-error" style="display:none;" id="f_{{parameter.name}}"
                    openlmis-message="error.number.only"></span>
            </div>

            <div ng-if="parameter.dataType === 'java.lang.String' && parameter.selectValues.length === 0">
              <input type="text" id="string_{{parameter.name}}" ng-trim="false"
                     ng-model="parameterMap[parameter.name]" ng-change="refreshParams()"/>
            </div>

            <div ng-if="parameter.dataType === 'java.lang.String' && parameter.selectValues.length > 0">
                <select id="string_{{parameter.name}}" ng-trim="false"
                       ng-model="parameterMap[parameter.name]"
                       ng-options="i for i in parameter.selectValues"
                       ng-change="refreshParams()"/>
            </div>

            <div ng-if="isInvalid(parameter.dataType)">
              <span id="unSupportedDataType_{{parameter.name}}" class="note label-required unSupportedDataType">Unsupported data type</span>
            </div>
          </td>

          <td id="description_{{parameter.name}}" class="span5"><em ng-bind="parameter.description"></em></td>
        </tr>
        <tr class="action-row">
          <td></td>
          <td class="center-justified">
            <a class="btn btn-primary" id="pdfTableButton" ng-href="/reports/{{template.id}}/pdf?{{params}}" target="_blank"
               openlmis-message="report.type.pdf"></a>
            <a class="btn btn-primary" id="xlsTableButton" ng-href="/reports/{{template.id}}/xls?{{params}}" target="_blank"
               openlmis-message="report.type.xls"></a>
            <a class="btn btn-primary" id="csvTableButton" ng-href="/reports/{{template.id}}/csv?{{params}}" target="_blank"
               openlmis-message="report.type.csv"></a>
            <a class="btn btn-primary" id="htmlTableButton" ng-href="/reports/{{template.id}}/html?{{params}}" target="_blank"
               openlmis-message="report.type.html"></a>
          </td>
          <td></td>
        </tr>
      </tbody>
    </table>

    <span ng-if="!parameters.length">
      <a class="btn btn-primary" id="pdfButton" ng-href="/reports/{{template.id}}/pdf?{{params}}" target="_blank"
         openlmis-message="report.type.pdf"></a>
      <a class="btn btn-primary" id="xlsButton" ng-href="/reports/{{template.id}}/xls?{{params}}" target="_blank"
         openlmis-message="report.type.xls"></a>
      <a class="btn btn-primary" id="csvButton" ng-href="/reports/{{template.id}}/csv?{{params}}" target="_blank"
         openlmis-message="report.type.csv"></a>
      <a class="btn btn-primary" id="htmlButton" ng-href="/reports/{{template.id}}/html?{{params}}" target="_blank"
         openlmis-message="report.type.html"></a>
    </span>

  </div>
</div>
